package cn.iocoder.yudao.module.wine.dal.mysql.advertisement;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.wine.controller.app.advertisement.vo.AppAdvertisementPageReqVO;
import cn.iocoder.yudao.module.wine.dal.dataobject.advertisement.AdvertisementDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.wine.controller.admin.advertisement.vo.*;

/**
 * 广告信息 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface AdvertisementMapper extends BaseMapperX<AdvertisementDO> {

    default PageResult<AdvertisementDO> selectPage(AdvertisementPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<AdvertisementDO>()
                .likeIfPresent(AdvertisementDO::getName, reqVO.getName())
                .eqIfPresent(AdvertisementDO::getImageUrl, reqVO.getImageUrl())
                .eqIfPresent(AdvertisementDO::getSort, reqVO.getSort())
                .betweenIfPresent(AdvertisementDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(AdvertisementDO::getCode, reqVO.getCode())
                .eqIfPresent(AdvertisementDO::getType, reqVO.getType())
                .betweenIfPresent(AdvertisementDO::getStartTime, reqVO.getStartTime())
                .betweenIfPresent(AdvertisementDO::getEndTime, reqVO.getEndTime())
                .orderByDesc(AdvertisementDO::getId));
    }

    default List<AdvertisementDO> getAdvertisementList(AppAdvertisementPageReqVO reqVO){
        return selectList(new LambdaQueryWrapperX<AdvertisementDO>()
                .likeIfPresent(AdvertisementDO::getName, reqVO.getName())
                .eqIfPresent(AdvertisementDO::getSort, reqVO.getSort())
                .eqIfPresent(AdvertisementDO::getCode, reqVO.getCode())
                .eqIfPresent(AdvertisementDO::getType, reqVO.getType())
                .betweenIfPresent(AdvertisementDO::getStartTime, reqVO.getStartTime())
                .betweenIfPresent(AdvertisementDO::getEndTime, reqVO.getEndTime())
                .orderByAsc(AdvertisementDO::getSort));
    }
}
